package com.shadow.baiqun.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shadow.baiqun.R;

import java.util.List;

/**
 * @author zy
 * on 2018/5/24
 */
public class TableHeadView extends LinearLayout {
    public TableHeadView(Context context) {
        this(context, null);
    }

    public TableHeadView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TableHeadView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        setOrientation(HORIZONTAL);
    }

    public void setHeaders(List<String> list) {
        if (getChildCount() > 0) {
            removeAllViews();
        }
        if (list != null) {
            LayoutParams layoutParams = new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.weight = 1;
            for (String s : list) {
                TextView tv = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.view_head,null);
                tv.setText(s);
                addView(tv, layoutParams);
            }
        }
    }
}
